package com.ews.onlineexchange.model;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Transient;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

@Embeddable
public class TradeReportData implements Serializable {

	/**
	 * 
	 */
	private static final long	serialVersionUID	= 1L;

	private BigDecimal			offer;
	private List<Attachment>	socialSecurityDatas;
	private List<Attachment>	effectDatas;
	private List<Attachment>	personnelCertDatas;
	private List<Attachment>	otherDatas;

	private BigDecimal			offerScore;
	private BigDecimal			socialSecurityScore;
	private BigDecimal			effectScore;
	private BigDecimal			personnelCertScore;
	private BigDecimal			otherScore;

	@NotNull
	@Min( 0L )
	@Column( name = "applyOffer" )
	public BigDecimal getOffer() {
		return offer;
	}

	public void setOffer( BigDecimal offer ) {
		this.offer = offer;
	}

	@OneToMany ( cascade = CascadeType.ALL )
	@JoinTable( name = "TRADE_SOCIALECURITYDATAS" )
	public List<Attachment> getSocialSecurityDatas() {
		return socialSecurityDatas;
	}

	public void setSocialSecurityDatas( List<Attachment> socialSecurityDatas ) {
		this.socialSecurityDatas = socialSecurityDatas;
	}

	@OneToMany ( cascade = CascadeType.ALL )
	@JoinTable( name = "TRADE_EFFECTDATAS" )
	public List<Attachment> getEffectDatas() {
		return effectDatas;
	}

	public void setEffectDatas( List<Attachment> effectDatas ) {
		this.effectDatas = effectDatas;
	}

	@OneToMany ( cascade = CascadeType.ALL )
	@JoinTable( name = "TRADE_PERSONELCERTDATAS" )
	public List<Attachment> getPersonnelCertDatas() {
		return personnelCertDatas;
	}

	public void setPersonnelCertDatas( List<Attachment> personnelCertDatas ) {
		this.personnelCertDatas = personnelCertDatas;
	}

	@OneToMany ( cascade = CascadeType.ALL ) 
	@JoinTable( name = "TRADE_OTHERDATAS" )
	public List<Attachment> getOtherDatas() {
		return otherDatas;
	}

	public void setOtherDatas( List<Attachment> otherDatas ) {
		this.otherDatas = otherDatas;
	}

	@Min( 0L )
	public BigDecimal getOfferScore() {
		return offerScore;
	}

	public void setOfferScore( BigDecimal offerScore ) {
		this.offerScore = offerScore;
	}

	@Min( 0L )
	public BigDecimal getSocialSecurityScore() {
		return socialSecurityScore;
	}

	public void setSocialSecurityScore( BigDecimal socialSecurityScore ) {
		this.socialSecurityScore = socialSecurityScore;
	}

	@Min( 0L )
	public BigDecimal getEffectScore() {
		return effectScore;
	}

	public void setEffectScore( BigDecimal effectScore ) {
		this.effectScore = effectScore;
	}

	@Min( 0L )
	public BigDecimal getPersonnelCertScore() {
		return personnelCertScore;
	}

	public void setPersonnelCertScore( BigDecimal personnelCertScore ) {
		this.personnelCertScore = personnelCertScore;
	}

	@Min( 0L )
	public BigDecimal getOtherScore() {
		return otherScore;
	}

	public void setOtherScore( BigDecimal otherScore ) {
		this.otherScore = otherScore;
	}
	
	@Transient
	public BigDecimal getSumScore() {
		BigDecimal sum = new BigDecimal( 0 );
		
		if ( getOfferScore() != null) {
			sum = sum.add( getOfferScore() );			
		}
		
		if ( getSocialSecurityScore() != null ) {
			sum = sum.add( getSocialSecurityScore() );
		}
		
		if ( getEffectScore() != null) {
			sum = sum.add( getEffectScore() );			
		}
		
		if ( getPersonnelCertScore() != null) {
			sum = sum.add( getPersonnelCertScore() );			
		}
		
		if ( getOtherScore() != null) {
			sum = sum.add( getOtherScore() );			
		}
		
		return sum;
	}
	
	@Transient
	public boolean isAssessOver() {
		return true;
	}
}
